@model CountryModel

@if (Model.Id > 0)
{
    <div class="card-body">
        @await Html.PartialAsync("Table", new DataTablesModel
        {
            Name = "states-grid",
            UrlRead = new DataUrl("States", "Country", new RouteValueDictionary { [nameof(StateProvinceSearchModel.CountryId)] = Model.StateProvinceSearchModel.CountryId }),
            UrlDelete = new DataUrl("StateDelete", "Country", null),
            Length = Model.StateProvinceSearchModel.PageSize,
            LengthMenu = Model.StateProvinceSearchModel.AvailablePageSizes,
            ColumnCollection = new List<ColumnProperty>
            {
                new ColumnProperty(nameof(StateProvinceModel.Name))
                {
                    Title = T("Admin.Configuration.Countries.States.Fields.Name").Text,
                    Width = "300"
                },
                new ColumnProperty(nameof(StateProvinceModel.Abbreviation))
                {
                    Title = T("Admin.Configuration.Countries.States.Fields.Abbreviation").Text,
                    Width = "150"
                },
                new ColumnProperty(nameof(StateProvinceModel.Published))
                {
                    Title = T("Admin.Configuration.Countries.States.Fields.Published").Text,
                    Width = "100",
                    ClassName = NopColumnClassDefaults.CenterAll,
                    Render = new RenderBoolean()
                },
                new ColumnProperty(nameof(StateProvinceModel.DisplayOrder))
                {
                    Title = T("Admin.Configuration.Countries.States.Fields.DisplayOrder").Text,
                    Width = "100",
                    ClassName =  NopColumnClassDefaults.CenterAll
                },
                new ColumnProperty(nameof(StateProvinceModel.Id))
                {
                    Title = T("Admin.Common.Edit").Text,
                    Width = "100",
                    ClassName = NopColumnClassDefaults.Button,
                    Render = new RenderCustom("renderColumnEdit")
                },
                new ColumnProperty(nameof(StateProvinceModel.Id))
                {
                    Title = T("Admin.Common.Delete").Text,
                    Width = "100",
                    Render = new RenderButtonRemove(T("Admin.Common.Delete").Text),
                    ClassName = NopColumnClassDefaults.Button
                }
            }
        })
    </div>
    <div class="card-footer">
        <div width="100%">
            <button type="submit" id="btnAddNewState"
                    onclick="javascript:OpenWindow('@(Url.Action("StateCreatePopup", "Country", new { countryId = Model.Id, btnId = "btnRefresh", formId = "country-form" }))', 800, 450, true); return false;"
                    class="btn btn-primary">
                @T("Admin.Configuration.Countries.States.AddNew")
            </button>
            <button type="submit" id="btnRefresh" style="display: none"></button>
            <script>
                $(document).ready(function () {
                    $('#btnRefresh').click(function () {
                        //refresh grid
                        updateTable('#states-grid');

                        //return false to don't reload a page
                        return false;
                    });
                });
            </script>
        </div>
    </div>
}
else
{
    <div class="card-body">
        @T("Admin.Configuration.Countries.States.SaveBeforeEdit")
    </div>
}

<script>
    function renderColumnEdit(data, type, row, meta) {
        return '<button onclick=\"javascript:OpenWindow(\'@Url.Content("~/Admin/Country/StateEditPopup/")' + data + '?btnId=btnRefresh&formId=country-form\', 800, 400, true); return false;\" class="btn btn-default"><i class="fas fa-pencil-alt"></i>@T("Admin.Common.Edit").Text</button>';
    }
</script>